﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;


namespace PRE
{
    using System.Configuration;

    public partial class FrmMain : RibbonForm
    {
        private const string STR_LOGIN = "Đăng &nhập";
        private const string STR_LOGOUT = "Đăng &xuất";

        public static UTL.Session _sss = new UTL.Session();
        public static string _User;
        public FrmMain()
        {
            InitializeComponent();
            InitSkinGallery();
            //InitGrid();

        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }


        private void FrmMain_Load(object sender, EventArgs e)
        {
        //    try
        //    {
        //        Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        //        string st = _config.ConnectionStrings.ConnectionStrings[1].ConnectionString;
        //        DAL.BaseDAL.DbName = st.Split(';')[1].Split('=')[1];
        //    }
        //    catch (Exception)
        //    {
        //        DAL.BaseDAL.DbName = DAL.BaseDAL.DefautDbName;
        //    }

            bbiDangnhap_ItemClick(sender, null);
        }

        // ----------------------------- Các items chức năng -------------------------

        private void EnableMenu()
        {
            switch (_sss.Role)
            {
                case UTL.Session.Roles.Admin:

                    break;

                case UTL.Session.Roles.Manager:
                    rpgNguoidung.Visible = false;
                    rpgDoanhthu.Visible = true;
                    break;

                case UTL.Session.Roles.User:
                    rpgNguoidung.Visible = false;
                    rpgDoanhthu.Visible = false;
                    break;

                default:
                    break;
            }
        }



        #region Trang chủ

        #region Hệ thống

        private void bbiDangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (bbiDangnhap.Caption == STR_LOGOUT)
            {
                _sss.Login = false;
                bbiDangnhap.Caption = STR_LOGIN;

                bbiDongtatca_ItemClick(sender, e);
            }

            Login.FrmLogin x = new Login.FrmLogin();
            x.ShowDialog();

            if (_sss.Login)
            {
                bsiUser.Caption = _sss.Name;
                _User = _sss.Acc;
                bbiDangnhap.Caption = STR_LOGOUT;

                rpDanhmuc.Visible = true;
                rpThongke.Visible = true;
                rpgNguoidung.Visible = true;
                rpgDangky.Visible = true;
                bbiDoimatkhau.Visibility = BarItemVisibility.Always;
            }
            else
            {
                rpDanhmuc.Visible = false;
                rpThongke.Visible = false;
                rpgNguoidung.Visible = false;
                rpgDangky.Visible = false;
                rpgDiemthi.Visible = false;
                bbiDoimatkhau.Visibility = BarItemVisibility.Never;
            }

            EnableMenu();
        }

        private void bbiDoimatkhau_ItemClick(object sender, ItemClickEventArgs e)
        {
            Login.FrmChangePass frm = new Login.FrmChangePass();
            frm._User = _User;
            frm.ShowDialog();
        }

        #endregion

        #region Người dùng

        private void bbiThanhvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmThanhvien) return;
            var frm = new Catalog.FrmThanhvien() { MdiParent = this };

            frm.Show();
        }

        private void bbiVaitro_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmVaitro) return;
            var frm = new Catalog.FrmVaitro() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Đăng ký

        private void bbiDangky_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Register.FrmDangky) return;
            var frm = new Register.FrmDangky() { MdiParent = this };

            frm.Show();
        }

        private void bbiDSDangky_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Register.FrmDSDangky) return;
            var frm = new Register.FrmDSDangky() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Điểm thi

        #region Nhập điểm

        private void bbiNhapdiem_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmNhapdiem) return;
            var frm = new Catalog.FrmNhapdiem() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Xem điểm

        private void bbiXemdiem_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmXemdiem) return;
            var frm = new Catalog.FrmXemdiem() { MdiParent = this };

            frm.Show();
        }


        #endregion

        #endregion

        #region Exit

        private void bbiDongtatca_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var frm in MdiChildren) frm.Close();
        }

        private void bbiThoat_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Close();
        }

        #endregion

        #endregion


        #region Danh mục

        #region Khóa học

        private void bbiKhoahoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmKhoahoc) return;
            var frm = new Catalog.FrmKhoahoc() { MdiParent = this };

            frm.Show();
        }

        private void bbiLophoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmLophoc) return;
            var frm = new Catalog.FrmLophoc() { MdiParent = this };

            frm.Show();
        }

        private void bbiLoaichungchi_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmLoaichungchi) return;
            var frm = new Catalog.FrmLoaichungchi() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Danh mục

        private void bbiHocvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmHocvien) return;
            var frm = new Catalog.FrmHocvien() { MdiParent = this };

            frm.Show();
        }

        private void bbiGiaovien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmGiaovien) return;
            var frm = new Catalog.FrmGiaovien() { MdiParent = this };

            frm.Show();
        }

        private void bbiPhonghoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmPhonghoc) return;
            var frm = new Catalog.FrmPhonghoc() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Lịch dạy

        private void bbiCahoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmCahoc) return;
            var frm = new Catalog.FrmCahoc() { MdiParent = this };

            frm.Show();
        }

        private void bbiDaylop_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmDaylop) return;
            var frm = new Catalog.FrmDaylop() { MdiParent = this };

            frm.Show();
        }

        private void bbiDaybu_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmDaybu) return;
            var frm = new Catalog.FrmDaybu() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Thông tin

        private void bbiTKB_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmTKB) return;
            var frm = new Catalog.FrmTKB() { MdiParent = this };

            frm.Show();
        }

        private void bbiPhieuthu_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmXemphieuthu) return;
            var frm = new Catalog.FrmXemphieuthu() { MdiParent = this };

            frm.Show();
        }

        private void bbiCapchungchi_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Register.FrmCapchungchi) return;
            var frm = new Register.FrmCapchungchi() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #endregion


        #region Thống kê

        #region Học viên

        private void bbiSLHV_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Report_Catalog.Frm_Thongke_Hocvien) return;
            var frm = new Report_Catalog.Frm_Thongke_Hocvien() { MdiParent = this };

            frm.Show();
        }

        private void bbiSlHvTheoLop_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Report_Catalog.FrmThongke_hv_theolop) return;
            var frm = new Report_Catalog.FrmThongke_hv_theolop() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Doanh thu

        private void bbiDoanhthu_theothang_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Report_Catalog.FrmThongke_Doanhthu_Theolop) return;
            var frm = new Report_Catalog.FrmThongke_Doanhthu_Theolop() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Thông tin

        private void bbiBangdiemtungkhoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Report_Catalog.FrmBangdiem_Theokhoa) return;
            var frm = new Report_Catalog.FrmBangdiem_Theokhoa() { MdiParent = this };

            frm.Show();
        }

        private void bbiBangdiem_Theolop_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Report_Catalog.FrmBangdiem_Theolop) return;
            var frm = new Report_Catalog.FrmBangdiem_Theolop() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #endregion


        #region Giúp đỡ

        private void bbiGioithieu_ItemClick(object sender, ItemClickEventArgs e)
        {
            About.FrmAbout frm = new About.FrmAbout();
            frm.ShowDialog();
        }


        #endregion

        private void iExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Close();
        }

        
    
        

        

        

     




    }
}